<?php
/*
This main View class/Theme controller which is extended from appModel
*/

include 'models/modeller.php';

class appView extends appModel
{
	var $theme;
	var $template;
	var $page;
	var $title;
	//Holds the variables passed by controller set() function
	var $viewVars;
	
	
	function __construct()
	{
		//parent::__construct($theme);
		//echo 'I am contructor of appView class';
		
	}
	
	function setTheme($theme)
	{
		$this -> theme = $theme;
		$this -> template = 'templates/'.$theme;
	}
	
	
	function render($title = '')
	{
		//print_r($this -> viewVars);
		//Parsing the viewVars into variables
		if($this -> viewVars)
		{
			foreach($this -> viewVars as $key => $value) {
				if(!is_array($value)){
					${$key} = trim(rawurldecode($value));
					//echo "$key $value<br>";
				}
				else{
					${$key} = $value;
				}	
			}
		}
		
		$this -> title = SITETITLE . ' | '. $title;
		require_once ('themes/'.$this -> theme.'/header.php');
		
		require_once ('themes/'.$this -> theme.'/'.$this -> page.'.php');
		
		require_once ('themes/'.$this -> theme.'/footer.php');
		
	}
	
	function renderStatus($cmd)
	{
		if($cmd)
		{
			echo '<div class="redBox">';
			echo $cmd;
			echo '</div>';
		}
	}

}
?>